package com.blog.wl2023.entity.response;

import com.blog.wl2023.constant.Code;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @author wule
 * @date 2023-10-14  16:37
 * @desc 分页信息返回类
 */
@AllArgsConstructor
@NoArgsConstructor
@Data
public class PageResult  implements Serializable {
	/**
	 * 业务响应码
	 */
	private Integer code;
	/**
	 * 响应信息
	 */
	private String message;
	/**
	 * 响应数据
	 */
	private Object data;

	/**
	 * 总条数
	 */
	 private Long totalElements;
	/**
	 * 总页数
	 */
	 private Integer totalPages;

	/**
	 * 返回成功，带数据
	 *
	 * @param data
	 */
	public static PageResult ok(Object data,Long totalElements,Integer totalPages) {
		PageResult pageResult = new PageResult();
		pageResult.setCode(Code.SUCCESS.getCode());
		pageResult.setData(data);
		pageResult.setTotalElements(totalElements);
		pageResult.setTotalPages(totalPages);
		return pageResult;
	}


}
